# #!/usr/bin/env python
# # -*- coding: utf-8 -*-
# # @Date    : 2014-08-18 15:48:48
# # @Author  : shitao.tommy (hero007asd@gmail.com)
# # @Link    : http://example.org
# # @Version : $Id$

# from web.handler.api import BaseApiHandler
# from lib.tornado_routes import route
# from tornado import gen
# from tornado.web import asynchronous

# head_title = '测试'

# @route(r'api/test/?',name='apitest')
# class TestApi(BaseApiHandler):
#     '''
#     @title 测试用的登陆接口
#     @method get
#     @param username 姓名 12位最长
#     @param password 密码 md5加密
#     @return {return_code:1, message:null}
#     @returnfield status 登陆状态 1.登陆成功2.登陆失败
#     @description test api for description
#     '''
#     @gen.coroutine
#     def get(self):
#         # from web.models.test import Test
#         # t = Test()
#         # self.write(t.getAll())
#         print self.request

# @route(r'api/test2')
# class Test2Api(BaseApiHandler):
#     @asynchronous
#     @gen.coroutine
#     def get(self):
#         for x in xrange(20):
#             yield gen.sleep(2)
#         self.finish()

# from vendor.ttcelery.task import sendmail
# @route(r'api/celery', name='apicelery')
# class TestCelery(BaseApiHandler):
#     @asynchronous
#     @gen.coroutine
#     def get(self):
#         # response = yield gen.Task(add.apply_async, args=[3,3])
#         # response = yield gen.Task(add.apply_async, args=[4,4])
#         # response = yield gen.Task(add.delay, args=[34,4])
#         # print str(response.result)
#         # self.write(str(response.result))
#         # yield gen.Task(add.apply_async, arg=[3,4])
#         # sendmail.apply_async()
#         from framework.mail.tmail import send_mail
#         send_mail(['13472843610@139.com',],"欧元/美元当前警示价","hello world！")
#         # print res
#         self.finish()



# import tornado_mysql
# from framework.db import conf
# @route(r'api/pymysql', name='pymysql')
# class TestPySql(BaseApiHandler):
#     @asynchronous
#     @gen.coroutine
#     def get(self):
#         # from tornado_mysql import pools
#         # pools.DEBUG = False
#         # WX_POOL = pools.Pool(dict(host='121.42.53.93', port=3306, user='root', passwd='1234567890', db='mysql'),
#         #             max_idle_connections=1,
#         #             max_recycle_sec=2)
#         # a = yield WX_POOL.execute("SELECT Host,User FROM user")
#         # print a.fetchall()
#         conn = yield tornado_mysql.connect(host=conf.host, port=conf.port, user=conf.user, passwd=conf.passwd, db='zhaohang_db')
#         cur = conn.cursor()
#         yield cur.execute("SELECT * FROM tp_api")

#         cur.close()
#         conn.close()
#         self.finish()


# from tornado_mysql import pools, connect
# @route(r'api/pymysql_pool', name='pymysql_pool')
# class TestPy1Sql(BaseApiHandler):
#     @asynchronous
#     @gen.coroutine
#     def get(self):
#         # from tornado_mysql import pools
#         # pools.DEBUG = False
#         # WX_POOL = pools.Pool(dict(host='121.42.53.93', port=3306, user='root', passwd='1234567890', db='mysql'),
#         #             max_idle_connections=1,
#         #             max_recycle_sec=2)
#         # a = yield WX_POOL.execute("SELECT Host,User FROM user")
#         # print a.fetchall()

#         WX_POOL = pools.Pool(
#             dict(host=conf.host, port=conf.port, user=conf.user,passwd=conf.passwd, db='zhaohang_db',charset='utf8'),
#             max_idle_connections=10,
#             max_recycle_sec=5)
#         yield WX_POOL.execute("SELECT * FROM tp_api")
#         # conn = yield tornado_mysql.connect(host=conf.host, port=conf.port, user=conf.user, passwd=conf.passwd, db='zhaohang_db')
#         # cur = conn.cursor()
#         # yield cur.execute("SELECT id,name FROM t_test")
#         # print(cur.description)
#         # for row in cur:
#         #    print(row)
#         # cur.close()
#         # conn.close()
#         self.finish()

# # ioloop.IOLoop.current().run_sync(main)

# from service.task import testtasks as tasks
# @route(r'api/tcelery', name='tcelery')
# class GenMultipleAsyncHandler(BaseApiHandler):
#     @asynchronous
#     @gen.coroutine
#     def get(self):
#         # r1, r2 = yield [gen.Task(tasks.sleep.apply_async, args=[2]),
#         #                 gen.Task(tasks.add.apply_async, args=[1, 2])]
#         # self.write(str(r1.result))
#         # self.write(str(r2.result))
#         # r1= yield gen.Task(tasks.add.apply_async, args=[2,2])
#         # print str(r1.result)
#         result = tasks.add.delay(1,2)
#         # print result.ready()
#         # print result.get(timeout=1)
#         self.finish()


